package org.example.travel_web.controller.user;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.example.travel_web.dto.user.UserReq;
import org.example.travel_web.dto.user.UserUpdateReq;
import org.example.travel_web.entity.UserET;
import org.example.travel_web.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/info")
@Tag(name = "用户个人信息管理")
public class UserInfoController {
    @Resource
    private UserService userService;

    @GetMapping
    @Operation(summary = "查询用户信息")
    public UserET getUserInfo() {
        return userService.getById(StpUtil.getLoginIdAsLong());
    }

    @PostMapping
    @Operation(summary = "修改用户信息")
    public void updateUserInfo(@Valid UserUpdateReq req) {
        UserReq bean = BeanUtil.toBean(req, UserReq.class);
        bean.setUid(StpUtil.getLoginIdAsLong());
        userService.updateUser(bean);
    }
}
